package org.example.comp_algorithm_back.service.impl;

import org.example.comp_algorithm_back.algorithm.CompKey;
import org.example.comp_algorithm_back.common.CommonResponse;
import org.example.comp_algorithm_back.util.PathClass;
import org.example.comp_algorithm_back.dto.DataPreprocessDTO;
import org.example.comp_algorithm_back.service.DataPreprocessingService;
import org.example.comp_algorithm_back.util.DataCleanUtil;
import org.example.comp_algorithm_back.vo.KeywordVo;
import org.springframework.stereotype.Service;

import java.io.*;
import java.util.ArrayList;

@Service
public class DataPreprocessingServiceImpl implements DataPreprocessingService {
    @Override
    public CommonResponse<Object> dataPreprocessing(DataPreprocessDTO dataPreprocessDTO) {
        String[] words = dataPreprocessDTO.getWords();          //种子关键词集合
        int num = dataPreprocessDTO.getNum();                   //需要的竞争关键词个数
        int choice = dataPreprocessDTO.getChoice();             //分词库选择
        ArrayList<KeywordVo> result = new ArrayList<>();

        //搜索文件初步清理
        DataCleanUtil.Check();

        //提取种子关键词并开始算法
        try {
            for (String word : words) {
                KeywordVo vo = new KeywordVo();
                vo.setSeedWord(word);
                System.out.println("compkey算法开始，种子关键词为“" + word + "”...");
                CompKey.compkey(word, num, vo, choice);
                result.add(vo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CommonResponse.createForSuccess("算法完毕",result);
    }
}
